package com.itheima.mapper;

import com.github.pagehelper.Page;
import com.itheima.pojo.Order;
import com.itheima.pojo.OrderStatusCount;
import com.itheima.pojo.OrderVO;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.time.LocalDate;
import java.util.List;

@Mapper
public interface OrderMapper {

    /**
     * 分页查询
     * @param queryString
     * @return
     */
    Page<OrderVO> pageQuery(String queryString);

    /**
     * 根据id查询
     * @param id
     * @return
     */
    @Select("select * from t_order where id = #{id}")
    Order selectById(Integer id);

    /**
     * 更新预约信息
     * @param order
     */
    void update(Order order);

    /**
     * 根据日期查询预约数量
     * @param begin
     * @param end
     * @return
     */
    @Select("select order_status as status,count(*) as count from t_order where order_date >= #{begin} and order_date < #{end} group by order_status")
    List<OrderStatusCount> countOrderByDate(LocalDate begin, LocalDate end);

    /**
     * 查询所有预约数量
     * @return
     */
    @Select("select count(*) from t_order")
    Integer countAll();

    /**
     * 根据套餐id查询预约数量
     * @param setmealId
     * @return
     */
    @Select("select count(*) from t_order where setmeal_id = #{setmealId}")
    Integer countBySetmealId(Integer setmealId);
}
